//把common配置作为基准模板配置文件
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require("vue-loader/lib/plugin")

module.exports = {
  //默认模式
  mode: 'none',
  //入口
  entry: './src/main.js',
  output: {
    filename: 'bundle.js',
    //生成的目录
    path: path.resolve('dist')
  },
  module: {
    rules: [
      //务必排除node_modules，否则可能造成污染依赖
      //vue
      {
        test: /\.vue$/,
        exclude: /node_modules/,
        use: 'vue-loader'
      },
      //js
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      },
      //style
      {
        test: /\.less$/,
        exclude: /node_modules/,
        use: ['style-loader', 'css-loader', 'less-loader']
      },
      {
        test: /\.css$/,
        exclude: /node_modules/,
        use: ['style-loader', 'css-loader']
      },
      //image
      {
        test: /\.png$/,
        exclude: /node_modules/,
        use: {
          loader: 'url-loader',
          options: {
            //esModule不给的话会加载不了
            esModule: false,
            limit: 40960
          }
        }
      }
    ]
  },
  plugins: [
    //给定插件，处理
    new HtmlWebpackPlugin({
      title: 'HelloWorld',
      template: './public/index.html',
      favicon: './public/favicon.ico'
    }),
    new VueLoaderPlugin(),
    //处理模板的BASE
    new webpack.DefinePlugin({
      BASE_URL: '"/"'
    }),
  ]
}